package com.ssy.lingxi.report.repository.report;

import com.ssy.lingxi.report.entity.report.ContractDayReportDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 合同日报表[平台首页：采购统计]
 * @author ds
 * @date 2021/6/10
 * @version 2.0.0
 */
public interface ContractDayReportRepository extends JpaRepository<ContractDayReportDO, Long>, JpaSpecificationExecutor<ContractDayReportDO> {

    /**
     * 删除指定范围订单日报表
     * @author 伍将
     * @date 2020/11/9
     * @param startTime:
     * @param endTime:
     * @return void
     **/
    void deleteByDateTimeBetween(LocalDateTime startTime, LocalDateTime endTime);

    /**
     * 查询指定范围订单日统计数据
     * @author 伍将
     * @date 2020/11/10
     * @param startTime:
     * @param endTime:
     * @return java.util.List<com.ssy.lingxi.report.entity.report.ContractDayReportDO>
     **/
    List<ContractDayReportDO> getAllByDateTimeBetween(LocalDateTime startTime, LocalDateTime endTime);

    /**
     * 根据报表时间查询日报表
     * @author 伍将
     * @date 2021/1/14
     * @param time: 报表时间
     * @return 日报表
     **/
    ContractDayReportDO findFirstByDateTime(LocalDateTime time);

    /**
     * 获取合同总数
     * @author ds
     * @date 2020/6/10
     * @return java.lang.Long
     **/
    @Query(value = "select sum(count) from rep_contract_day_report;", nativeQuery = true)
    Long getAllCount();

    /**
     * 获取合同总金额
     * @author ds
     * @date 2020/6/10
     * @return java.lang.Double
     **/
    @Query(value = "select sum(amount) from rep_contract_day_report;", nativeQuery = true)
    BigDecimal getAllAmount();
}

